package com.example.videoweb.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.videoweb.domain.HotVideo;
import com.example.videoweb.service.HotVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/hotVideo")
public class HotVideoController {

    @Autowired
    private HotVideoService hotVideoService;

    //修改热门视频
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public void update(HttpServletRequest request){
        String arr[] = request.getParameterValues("videoId");
        for (int i = 0 ; i < arr.length;i++){
            HotVideo hotVideo = new HotVideo();
            hotVideo.setId(i);
            hotVideo.setVideoId(Integer.parseInt(arr[i]));
            hotVideoService.update(hotVideo);
        }
    }

    //查询所有热门视频
    @RequestMapping(value = "/allHotVideo",method = RequestMethod.GET)
    public Object allHotVideo(HttpServletRequest request){
        return hotVideoService.allHotVideo();
    }
}
